<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>声音的风景</title>
<link rel="stylesheet" href="libs/weui.min.css">
<link rel="stylesheet" href="libs/jquery-weui.min.css">
  <link rel="stylesheet" href="styles/publish.css">
  <link rel="stylesheet" href="styles/home.css">
  <link rel="stylesheet" href="styles/report.css">
  <link rel="stylesheet" href="styles/share.css">
  <link rel="stylesheet" href="//at.alicdn.com/t/font_y6nj5lp5tuh4zpvi.css">
</head>
<body>
	<p class="report-title" id="workName"></p>
	<div id="downBtn" class="pub-progress">
		<i class="iconfont icon-kaishi" id="play"></i> <label id="totalTime">00:00</label>
		<div class="pub-pro-bar">
			<div class="pub-flag"></div>
		</div>
		<label id="pastTime">00:00</label>
	</div>

	<div class="report-title">作者解读</div>
	<p class="report-contents" id="description">

	</p>

  <div class="share-wrapper">
  <a id="createId" href="create.html">
    <div class="share-left">
      <div class="share-circle">
        <i class="iconfont" name="left">&#xe6d5;</i>
      </div>
      <p class="share-text">再录制一段</p>
    </div>
    </a>
    <a id="goodWorks" href="good.html">
    <div class="share-right">
      <div class="share-circle">
        <i class="iconfont" name="right">&#xe636;</i>
      </div>
      <p class="share-text">听优质作品</p>
    </div>
    </a>
  </div>

  <p class="share-invite">邀请好友作品有机会进入珍藏馆</p>

  <div class="share-line">
    <label>我要分享</label>
  </div>

  <div class="share-icon-list">
    <div class="share-icon" id="wxShare">
      <img src="images/s1.jpg"/>
    </div>
    <div class="share-icon">
      <img src="images/s2.jpg"/>
    </div>
    <div class="share-icon">
      <img src="images/s3.jpg"/>
    </div>
    <div class="share-icon">
      <img src="images/s4.jpg"/>
    </div>
    <div class="share-icon">
      <img src="images/s5.jpg"/>
    </div>
  </div>
<script src="libs/jquery.min.js"></script>
<script src="libs/jquery-weui.min.js"></script>
<script src="libs/common.js"></script>
<script src="https://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script src="js/play.js"></script>
<script>
$(document).ready(function(){
var url=window.location.search.substr(1);
var urls=$("#goodWorks").attr('href');
$("#goodWorks").attr('href',urls+"?"+url);
var url2=$("#createId").attr('href');
$("#createId").attr('href',url2+"?"+url);
});

$(document).ready(function(){
	 $.ajax({
		url: "/audio/wx/js/sign.htm?url="+escape(window.location.href),
		dataType: "json",
		cache: false,
		async:true,
		type: "get",
		success: function (rlt) {
			if(!rlt.result) {
				alert("初始化js参数错误！");
				return;
			}
			var data=rlt.data;
			wx.config({
				debug: false, // 开启调试模式
				appId: data.appId, // 必填，公众号的唯一标识
				timestamp: data.timestamp, // 必填，生成签名的时间戳
				nonceStr: data.nonceStr, // 必填，生成签名的随机串
				signature: data.signature,// 必填，签名
				jsApiList: ["startRecord",
				            "stopRecord",
				            "onVoiceRecordEnd",
				            "playVoice",
				            "pauseVoice",
				            "stopVoice",
				            "onVoicePlayEnd",
				            "uploadVoice",
				            "downloadVoice",
				            'checkJsApi',
				            'onMenuShareTimeline',
				            'onMenuShareAppMessage',
				            'onMenuShareQQ',
				            'onMenuShareWeibo',
				            'onMenuShareQZone'] 
			});
		},
		error: function () {

		}
	});
	 var worksId = getQueryString("worksId");
	 $.ajax({
			url : "works/detail.htm?id="+worksId,
			dataType : "json",
			cache : false,
			async : true,
			type : "get",
			success : function(rlt) {
				if (!rlt.result) {
					alert("查询录音失败！");
					return;
				}
				var data = rlt.data;
				serverIds.push(data.server_id);
				$("#description").html(data.description);
				$("#workName").html(data.works_name);
				$("#totalTime").html("00:"+data.durationStr);
				play.init($('#play'), data.duration);
			},
			error : function() {
				alert("网络异常！");
			}
		});
	 
	 var localIds=[];
	 var serverIds=[];
	 $("#downBtn").click(
				function(){
					if(serverIds.length==0){
						//播放
				        playAudio();
						return;
					}
					wx.downloadVoice({
					    serverId: serverIds.pop(), // 需要下载的音频的服务器端ID，由uploadVoice接口获得
					    isShowProgressTips: 1, // 默认为1，显示进度提示
					    success: function (res) {
					        var localId = res.localId; // 返回音频的本地ID
					        localIds.push(localId);
					        //播放
					        playAudio();
					    }
					});
				}
			);
		var currentLocalId="";
		var playAudio = function(){
					if(localIds.length==0){
						alert("本地没有片段！");
						return;
					}
					currentLocalId=localIds.pop();
					wx.playVoice({
					    localId: currentLocalId // 需要播放的音频的本地ID
					});
					localIds.push(currentLocalId);
				};
				
		$('#wxShare').click(function() {
			alert("adsfasdf");
			wx.onMenuShareTimeline({
			    title: '分享标题', // 分享标题
			    link: '', // 分享链接
			    imgUrl: '', // 分享图标
			    success: function () { 
			    	alert("分享成功");
			        // 用户确认分享后执行的回调函数
			    },
			    cancel: function () { 
			        // 用户取消分享后执行的回调函数
			    	alert("取消分享");
			    }
			});
		});		
			 			
});	
</script>
</body>
</html>